/**
 * @author Cheng Liu
 **/

#pragma once

#include "../Event/Events.h"
#include "IPluginFacade.h"
#include "../Event/IEventHandler.h"
#include "../Helper/HelperMarcos.h"
#include "../mfc/MenuManager/MenuManager.h"

class EventBus;
class CMainFrame;

class PluginFacade : public IPluginFacade {
	DECLARE_SINGLETON(PluginFacade)
public:

	//EventBus
	virtual void AttachListener(const Events::EventType& type, IEventHandler* handler);
	virtual bool DettachListener(const Events::EventType& type, IEventHandler* handler);
	virtual void ReleaseListener(const IEventHandler* handler);
	virtual void PublishEvent(Events::Event* event);

	//MenuManager
	virtual UINT RegisterCommand(IEventHandler* eventHandler);
	virtual void ReleaseCommand(UINT nCmd);

	virtual CMenu& GetMainMenu(){return menuManager->GetMenu();}
	virtual CMenu& GetFileMenu(){return *menuManager->GetMenu().GetSubMenu(0);}
	virtual CMenu& GetEditMenu(){return *menuManager->GetMenu().GetSubMenu(1);}
	virtual CMenu& GetViewMenu(){return *menuManager->GetMenu().GetSubMenu(2);}
	virtual CMenu& GetWindowMenu(){return *menuManager->GetMenu().GetSubMenu(3);}
	virtual CMenu& GetHelpMenu(){return *menuManager->GetMenu().GetSubMenu(4);}

	//ActiveWindow
	virtual BVHND GetActiveTextView();
	virtual void SetTextView(BVHND textView , BHND bhnd);
	virtual void SetFocus(BVHND view);

	//TextBuffers
	virtual BHND OpenTextBuffer(std::basic_string<TCHAR> pathFileName);
	virtual std::basic_string<TCHAR> GetTextBufferName(BHND bhnd);
	virtual std::vector<BHND> GetTextBufferList();
	
	//Syntax
	//virtual void SetColor(BVHND view, UINT color, int start, int length);

	//SetMenuManger
	void MenuManager(CMenuManager * val) { menuManager = val; }
	void MainFrm(CMainFrame * val) { mainFrm = val; }

	BOOL RegisterAccelKey(char* filePath, char* str, int cmd);

private:
	EventBus* eventBus;
	CMenuManager * menuManager;
	CMainFrame * mainFrm;
};
